﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibUtilities.dal;
using System.Data;
using System.Data.SqlClient;

namespace CLibArtreve.dal
{
    public class CountryDAL : SqlDatabase
    {
        #region CONSTRUCTORS
        public CountryDAL(string connectionString) : base(connectionString) { }
        #endregion

        #region OVERRIDE METHODS
        public override string ToString()
        {
            return "DATA ACCES LAYER: " + this.GetType().ToString();
        }
        #endregion

        #region GET METHODS
        public DataSet GetAllCountries()
        {
            try
            {
                return ExecuteDataSetWithCommonQuery(Queries.SELECTALLCOUNTRIES, null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet GetCountryById(Int64? id)
        {
            try
            {
                // MAKE A LIST OF PARAMETERS
                List<SqlParameter> parameters = new List<SqlParameter>();

                // MAKE PARAMETER
                SqlParameter parameter = new SqlParameter();
                parameter.DbType = DbType.Int64;
                parameter.Direction = ParameterDirection.Input;
                parameter.ParameterName = "country_id";
                parameter.Value = id;
                parameters.Add(parameter);

                // EXECUTE
                return ExecuteDataSetWithCommonQuery(Queries.SELECTCOUNTRYBYID, null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
